'##############
'Heizungs-Script
'##############

'Simuliert Wagenheizung, Zusatzheizung (evtl. auch gleich den Kьhlkreislauf mit...)

'(c) 20.02.2009 Rьdiger Hьlsmann

'Script Version: 1.1
'Omsi release: 1.0

'Needs:
'cockpit (fьr Taster und Regler)
'engine (for cooling circuit)
'door (for door opening status)

'Revision History:
'- Rьdiger Hьlsmann	17.02.2009	File created
'- Rьdiger Hьlsmann	20.02.2009	Batterietrennschalter eingefьgt (v1.1)
'- Marcel Kuhnt		10.08.2009	Added Revision History
'- Marcel & Rьdiger	23.09.2010	Parking Heater, room temperature
'- RЬdiger Hьlsmann	16.11.2010	Front heater
'- Rьdiger Hьlsmann	18.11.2010	Improved front heater
'- Rьdiger Hьlsmann	20.11.2010	Cabin heater, values adjusted
'- Rьdiger Hьlsmann	22.11.2010	Auxheat Schmitt-triggered, engine coolable by fan heaters
'- Rьdiger Hьlsmann	10.01.2011	Driver window airflow

'------------------------------------------------------------------------------------------






'----------------------
'	Init
'----------------------
{macro:heizung_init}
	(L.S.Weather_Temperature) (S.L.Cabinair_Temp)
	(L.S.Weather_AbsHum) (S.L.Cabinair_absHum)
{end}


{macro:heizung_frame}

	(M.L.standheizung_frame)	
	(M.L.cabinair_frame)
{end}








{macro:cabinair_frame}

'	Berechnung der Raten   Расчет параметров:
	(L.L.Cabinair_Temp) (L.S.Weather_Temperature) - (C.L.cabinair_Qrate_envir_factor) * (S.L.cabinair_Qrate_envir)

'	Direkte Ableitung der Motorwдrme in den Fahrgastraum   Прямой вывод тепла двигателя в салон 
	(L.L.engine_temperature_envir) (L.L.Cabinair_Temp) - (C.L.cabinair_Qrate_engine_factor) * (S.L.cabinair_Qrate_engine)

'	Вентиляторы отопителей
	(L.L.cp_heizluefter_sw) (L.L.elec_busbar_main) &&
	{if}
		(L.L.vent1_time) 5 <
		{if}
			(L.L.vent1_time) (L.S.Timegap) + (S.L.vent1_time)
		{endif}
		(L.L.vent1_time) (F.L.vent_speed_on) (S.L.vent1_speed)
		1 (S.L.salon_otopitel_1)
	{else}
		(L.L.vent1_time) 0 >
		{if}
			(L.L.vent1_time) (L.S.Timegap) - (S.L.vent1_time)
		{endif}
		(L.L.vent1_time) (F.L.vent_speed_off) (S.L.vent1_speed)
		0 (S.L.salon_otopitel_1)
	{endif}
	
	(L.L.otopitel_vent_1) (L.S.Timegap) (L.L.vent1_speed) * + (S.L.otopitel_vent_1)	
	
	(L.L.cp_heizluefter2_sw) (L.L.elec_busbar_main) &&
	{if}
		(L.L.vent2_time) 5 <
		{if}
			(L.L.vent2_time) (L.S.Timegap) + (S.L.vent2_time)
		{endif}
		(L.L.vent2_time) (F.L.vent_speed_on) (S.L.vent2_speed)
		1 (S.L.salon_otopitel_2)
	{else}
		(L.L.vent2_time) 0 >
		{if}
			(L.L.vent2_time) (L.S.Timegap) - (S.L.vent2_time)
		{endif}
		(L.L.vent2_time) (F.L.vent_speed_off) (S.L.vent2_speed)
		0 (S.L.salon_otopitel_2)
	{endif}
	
	(L.L.otopitel_vent_2) (L.S.Timegap) (L.L.vent2_speed) * + (S.L.otopitel_vent_2)
	
	
	

'	Berechnung der Solltemperatur am Frontheizgerдt
'	Расчет требуемой температуры на передний нагреватель

'	(L.L.Cabinair_Temp) (L.L.engine_temperature) (L.L.Cabinair_Temp) - (L.L.cockpit_heizregler_temp) * (C.L.heat_exchanger_effectivity) * + (S.L.fanheater_t_target)


'Berechnung der effektiven Gesamt-Luftaustauschflдche:
'Расчет эффективной общей площади воздухообмена:
	(L.L.door_1) (L.L.door_2) (L.L.door_3) + +
'	(L.L.door_0) +
	(L.L.door_2L) (L.L.door_2R) + +
	(L.L.door_3L) (L.L.door_3R) + + (C.L.cabinair_A_perdoor) *

	(L.L.cp_f1_l_pos) (L.L.cp_f2_l_pos) (L.L.cp_f3_l_pos) + +
	(L.L.cp_f1_r_pos) (L.L.cp_f2_r_pos) + +
	(L.L.hatch_1) (L.L.hatch_2) (L.L.hatch_3) + + + (C.L.cabinair_A_perwindow) * + 
'	(C.L.cabinair_A_driverwindow) (L.L.cp_fahrerfenster_pos) * +

'Berechnung des Gesamtvolumenstroms in die AuЯenwelt und umgekehrt (V zдhlt je Richtung, d.h. insgesamt wird 2*V bewegt)
'Расчет общего потока воздуха во внешний мир, и наоборот
	(L.L.velocity) 20 / abs (C.L.cabinair_windowdoor_minkmh) + (C.L.cabinair_windowdoor_effectivity) * 3.6 / * (S.L.cabinair_Vrate_doorwindow)
'Berechnung des Volumenstroms durch die Raumheizgerдte
'Расчет потока через обогреватель
	(C.L.cabinair_A_cabinheater) (L.L.cp_heizluefter_sw) 1 = * (L.L.elec_busbar_main) 1 = * (S.L.cabinair_Vrate_cabinheater)
	(C.L.cabinair_A_cabinheater) (L.L.cp_heizluefter2_sw) 1 = * (L.L.elec_busbar_main) 1 = * (S.L.cabinair_Vrate_cabinheater2)

'Berechnung der Temperaturrate durch Motor und Abstrahlung an die Umwelt...
'Расчет повышения температуры из-за двигателя
	(L.L.cabinair_Qrate_engine) (L.L.cabinair_Qrate_envir) - (C.L.cabinair_cvm) /
'...und Temperaturrate durch Passagiere...
'...температуры и количество пассажиров...
	(C.L.cabinair_T_passenger) (L.L.Cabinair_Temp) - (C.L.cabinair_V) / (C.L.cabinair_Vrate_passenger) * (L.L.humans_count) * +
'...und dieser durch die Volumenstrцme durch Fenster und Tьren:
'...Расход тепла через форточки и двери
	(L.S.Weather_Temperature) (L.L.Cabinair_Temp) - (C.L.cabinair_V) / (L.L.cabinair_Vrate_doorwindow) * +
'...und der Raumheizgerдte   и салонный отопитель...
	(L.L.engine_temperature) (C.L.heat_exchanger_effectivity) * (L.L.Cabinair_Temp) - (C.L.cabinair_V) / (L.L.cabinair_Vrate_cabinheater) * +
	(L.L.engine_temperature) (C.L.heat_exchanger_effectivity) * (L.L.Cabinair_Temp) - (C.L.cabinair_V) / (L.L.cabinair_Vrate_cabinheater2) * +
'...aufintegrieren   интеграция:
	(L.S.Timegap) * (L.L.Cabinair_Temp) + (S.L.Cabinair_Temp)
'Berechnung der Motorkьhlrate durch die Wдrmetauscher in den Heizgerдten:
'Расчет скорости прохода тепла двигателя через теплообменник в отопители:

	(L.L.fanheater_t_target) (L.L.Cabinair_Temp) - 0 max (C.L.cabinair_V) / (L.L.cabinair_Vrate_fanheater) * 
	(L.L.engine_temperature) (C.L.heat_exchanger_effectivity) * (L.L.Cabinair_Temp) max (L.L.Cabinair_Temp) - (C.L.cabinair_V) / (L.L.cabinair_Vrate_cabinheater) * +
	(C.L.cabinair_cvm) * 8 * (S.L.cabinair_Qrate_engine_fanheatcooling)

'Berechnung der Feuchtigkeitsrate durch Volstrцme mit den Passagieren:
'Расчет скорости увеличения влаги с пассажирами:
	(C.L.cabinair_absHum_passenger) (L.L.Cabinair_absHum) - (C.L.cabinair_V) / (C.L.cabinair_Vrate_passenger) * (L.L.humans_count) *
'Berechnung der Feuchtigkeitsrate durch Volumenstrцme mit der AuЯenwelt:
'Расчет скорости увеличения влажности от окружающего мира:
	(L.S.Weather_AbsHum) (L.L.Cabinair_absHum) - (C.L.cabinair_V) / (L.L.cabinair_Vrate_doorwindow) * +
'Berechnung der Feuchtigkeitsrate durch Frontheizgerдt
'Расчет скорости увеличения владжности от переднего отопителя:
	(L.S.Weather_AbsHum) (L.L.Cabinair_absHum) - (C.L.cabinair_V) / (L.L.cabinair_Vrate_fanheater) * (L.L.cockpit_heizregler_ventilation_mode) 1 >= * + (S.L.cabinair_test)
'... aufintegrieren   интеграция:
	(L.S.Timegap) * (L.L.Cabinair_absHum) + (S.L.Cabinair_absHum)

{end}

{macro:standheizung_frame}


	(L.L.cp_taster_standheizung_target) (L.L.elec_busbar_avail) &&
	{if}
		(L.L.standheizung_running) !
		{if}
			0 (S.L.standheizung_volume_stufe1) (S.L.standheizung_volume_stufe2)
			1 (S.L.standheizung_running)  
			0 (S.L.standheizung_stufe1_time_elapsed)
			1 (S.L.standheizung_stufe1) 
		{endif}
		1 (S.L.standheizung_target)
	
	{else}
		0 (S.L.standheizung_target)
	{endif}
	
'	Raufrцdeln der Timer:
	(L.L.standheizung_running)
	{if}
		(L.L.standheizung_stufe1_time_elapsed) (L.S.Timegap) + (S.L.standheizung_stufe1_time_elapsed)
		(L.L.standheizung_stufe2_time_elapsed) (L.S.Timegap) + (S.L.standheizung_stufe2_time_elapsed)
	{endif}

'	Einschalten der 2. Stufe:
	(L.L.standheizung_target) (L.L.standheizung_stufe1_time_elapsed) (C.L.standheizung_vorlauf) > &&
	(L.L.engine_temperature) (C.L.standheizung_brenner_t_ein) < &&
	{if}
		(L.L.standheizung_stufe2) !
		{if}
			0 (S.L.standheizung_stufe2_time_elapsed)
		{endif}
		1 (S.L.standheizung_stufe2)
	{endif}

'	Ausschalten der 2. Stufe:
	(L.L.standheizung_target) ! (L.L.standheizung_stufe2_time_elapsed) (C.L.standheizung_minlauf) > &&
	(L.L.engine_temperature) (C.L.standheizung_brenner_t_aus) > ||
	{if}
		(L.L.standheizung_stufe2)
		{if}
			0 (S.L.standheizung_stufe1_time_elapsed)
		{endif}
		0 (S.L.standheizung_stufe2) 
	{endif}

'	Ausschalten der 1. Stufe:
	(L.L.standheizung_target) ! (L.L.standheizung_stufe1_time_elapsed) (C.L.standheizung_nachlauf) > && 
	{if}
		0 (S.L.standheizung_stufe1)
	{endif}

	(L.L.standheizung_stufe1) 
	{if}
		(L.L.standheizung_volume_stufe1) (L.S.Timegap) 3 / + 1 min (S.L.standheizung_volume_stufe1)
	{else}
		(L.L.standheizung_volume_stufe1) (L.S.Timegap) 3 / - 0 max (S.L.standheizung_volume_stufe1)
		0.01 <
		{if}
			0 (S.L.standheizung_running)
		{endif}
	{endif}

	(L.L.standheizung_stufe2) 
	{if}
		(L.L.standheizung_volume_stufe2) (L.S.Timegap) 4 / + 1 min (S.L.standheizung_volume_stufe2)

'		Berechnung der Temperaturverдnderung:
		(C.L.heizung_Qrate_standheizung) (L.L.cabinair_Qrate_envir) - (C.L.engine_cvm_engine) / (L.S.Timegap) * (L.L.engine_temperature) + (S.L.engine_temperature) 


	{else}
		(L.L.standheizung_volume_stufe2) (L.S.Timegap) 4 / - 0 max (S.L.standheizung_volume_stufe2)
	{endif}

{end}
